package org.example.order.controller;

import lombok.RequiredArgsConstructor;
import org.example.order.entity.BufferTest;
import org.example.order.entity.User;
import org.example.order.service.OrderService;
import org.example.order.service.Test;
import org.example.order.service.UserService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

@RequestMapping("user")
@RestController
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;
    private List<BufferTest> data = new ArrayList<>();

    @PostMapping
    public ResponseEntity<Void> initUser() {
        userService.initUser();
        return ResponseEntity.noContent().build();
    }

    @PostMapping("add-user")
    public ResponseEntity<Void> addUser() {
        userService.addUser();
        return ResponseEntity.noContent().build();
    }

    @PostMapping("/test")
    public ResponseEntity<Void> test() {
        User user = User.builder()
                .userName("王老六")
                .userAccount(UUID.randomUUID().toString().replace("-", "").substring(26))
                .idCard("5122241997" + new Random().nextInt(100_000_000))
                .phoneNumber("199" + new Random().nextInt(100_000_000))
                .age(25)
                .build();
        data.add(new BufferTest(user));
        return ResponseEntity.noContent().build();
    }

}
